// 2024/1/15: 首个版本
// 2024/7/19: 增加Segment协议
// 2024/7/24: TransferStatElement增加SuccessBytes/FailBytes字段
// 2024/7/24: 增加DebugPrintProto
// 2024/7/24: 增加Protocol.AudioFrame
// 2024/7/25: 增加AgencyInput/OutputProto
// 2024/7/29: 增加SubscriberRequest/ResponseProto
// 2024/8/15: Protocol.MachineText改为Settings
// 2024/8/21: 增加BoxProto。SettingsProto增加AlwaysTransfer和UseBoxProtocol字段
// 2024/8/22: 新增AgencyInput/OutputProto计数字段
// 2024/8/26: 新增SettingsProto.AlwaysTransferAudio
// 2024/9/27: StopSessionProto增加RecordedSession字段
// 2024/10/10: 新增SubscriberRequestProto.CheckOnly
// 2024/10/23: 移除SettingsProto.MachineText/Enabled
// 2024/11/6: 新增独立任务相关协议
// 2024/12/6: 新增SettingsProto.TransferWithSessionInfo。新增SetVideoTransferProto和SecondProfileProto。新增110~117协议
// 2025/5/15: 总线通道数扩展至48
// 2025/5/26: 新增RoundTripTimeProto

using System;
using ASEva;
using SO = System.Reflection.ObfuscationAttribute;

namespace RemoteConsole
{
    [SO]
    enum Protocol
    {
        Disconnect = 0,
        Settings = 1,
        Abort = 2,
        StartSession = 3,
        StopSession = 4,
        StartupState = 5,
        TransferStat = 6,
        Prompt = 10,
        Print = 11,
        Confirm = 12,
        InputNumber = 13,
        InputString = 14,
        SingleSelect = 15,
        MultiSelect = 16,
        LoadFileData = 17,
        LoadedFileData = 18,
        SaveFileData = 19,
        SaveFileDataResult = 20,
        Box = 21,
        TaskStart = 22,
        TaskProgress = 23,
        TaskResult = 24,
        CancelTask = 25,
        SetVideoTransfer = 26,
        ManualTrigger = 100,
        BusMessage = 101,
        VideoFrame = 102,
        GeneralSample = 103,
        Signal = 104,
        PointCloud = 105,
        TransferSignalList = 106,
        TransferSampleList = 107,
        DebugPrint = 108,
        AudioFrame = 109,
        SessionManualTrigger = 110,
        SessionBusMessage = 111,
        SessionVideoFrame = 112,
        SessionGeneralSample = 113,
        SessionSignal = 114,
        SessionPointCloudSlice = 115,
        SessionAudioFrame = 116,
        SessionSecondMosaic = 117,
        SecondProfile = 118,
        AgencyInput = 190,
        AgencyOutput = 191,
        SubscriberRequest = 192,
        SubscriberResponse = 193,
        Segment = 200,
        RoundTripTime = 201,
    }

    [SO]
    class SettingsProto
    {
        public bool PassiveCommand { get; set; }
        public bool AlwaysTransferSample { get; set; }
        public bool AlwaysTransferDebugPrint { get; set; }
        public bool AlwaysTransferAudio { get; set; }
        public bool UseBoxProtocol { get; set; }
        public bool UseTaskProtocol { get; set; }
        public bool TransferWithSessionInfo { get; set; }
    }

    [SO]
    class RemoteBusConfig
    {
        public int Channel { get; set; } // 1~48
        public BusChannelType Type { get; set; }
    }

    [SO]
    class RemoteVideoConfig
    {
        public int Channel { get; set; } // 0~23
        public IntSize Size { get; set; }
        public VideoDataCodec Codec { get; set; }
        public int RecordFPS { get; set; }
        public bool AlignedFPS { get; set; }
    }

    [SO]
    class RemoteSampleConfig
    {
        public String Alias { get; set; }
        public String Title { get; set; }
    }

    [SO]
    class StartSessionProto
    {
        public ulong StartPosixMS { get; set; }
        public RemoteBusConfig[] BusConfigs { get; set; }
        public RemoteVideoConfig[] VideoConfigs { get; set; }
    }

    [SO]
    class StopSessionProto
    {
        public String RecordedSession { get; set; } // yyyy-MM-dd-HH-mm-ss
    }

    [SO]
    class StartupStateProto
    {
        public ApplicationMode Mode { get; set; }
        public ApplicationStatus Status { get; set; }
    }

    [SO]
    class TransferStatElement
    {
        public Protocol Protocol { get; set; }
        public int SuccessCount { get; set; }
        public int FailCount { get; set; }
        public ulong SuccessBytesPerSecond { get; set; }
        public ulong FailBytesPerSecond { get; set; }
    }

    [SO]
    class TransferStatProto
    {
        public TransferStatElement[] Elements { get; set; }
    }

    [SO]
    class PromptProto
    {
        public String Text { get; set; }
    }

    [SO]
    class CommonProto
    {
        public String Message { get; set; }
    }

    [SO]
    class PrintProto : CommonProto
    {}

    [SO]
    class ConfirmProto : CommonProto
    {}

    [SO]
    class InputNumberProto : CommonProto
    {
        public double Default { get; set; }
    }

    [SO]
    class InputStringProto : CommonProto
    {
        public String Default { get; set; }
    }

    [SO]
    class SingleSelectProto : CommonProto
    {
        public String[] Options { get; set; }
        public int Default { get; set; }
    }

    [SO]
    class MultiSelectProto : CommonProto
    {
        public String[] Options { get; set; }
        public int[] Default { get; set; }
    }

    [SO]
    class LoadFileDataProto : CommonProto
    {
        public String[] Extensions { get; set; }
    }

    [SO]
    class LoadedFileDataProto
    {
        public bool Loaded { get; set; }
        public String FilePath { get; set; }
        public int DataSize { get; set; }
    }

    [SO]
    class SaveFileDataProto : CommonProto
    {
        public String Extension { get; set; }
        public int DataSize { get; set; }
    }

    [SO]
    class SaveFileDataResultProto
    {
        public bool Saved { get; set; }
        public String FilePath { get; set; }
    }

    [SO]
    class BoxProto : CommonProto
    {
        public bool IsError { get; set; }
    }

    [SO]
    class TaskStartProto
    {
        public String GUID { get; set; }
        public String TaskClassID { get; set; }
        public String TaskConfig { get; set; }
        public String TaskTitle { get; set; }
    }

    [SO]
    class TaskProgressProto
    {
        public String GUID { get; set; }
        public double Progress { get; set; }
        public String Description { get; set; }
    }

    [SO]
    class TaskResultProto
    {
        public String GUID { get; set; }
        public bool Succeeded { get; set; }
        public bool Canceled { get; set; }
        public String Description { get; set; }
        public String ReturnValue { get; set; }
    }

    [SO]
    class CancelTaskProto
    {
        public String GUID { get; set; }
    }

    [SO]
    class SetVideoTransferProto
    {
        public int Channel { get; set; } // 0~23
        public bool Enable { get; set; }
    }

    [SO]
    class TransferSignalListProto
    {
        public String[] SignalIDs { get; set; }
    }

    [SO]
    class TransferSampleInfo
    {
        public String ChannelID { get; set; }
        public String Alias { get; set; }
        public String Title { get; set; }
    }

    [SO]
    class TransferSampleListProto
    {
        public TransferSampleInfo[] Samples { get; set; }
    }

    [SO]
    class GeneralSampleProto
    {
        public ulong HostPosix { get; set; }
        public String ChannelID { get; set; }
        public String[] Elements { get; set; }
    }

    [SO]
    class DebugPrintProto
    {
        public String Message { get; set; }
        public String Source { get; set; }
    }

    [SO]
    class ChannelProfileInfo
    {
        public String ID { get; set; }
        public int SourceCount { get; set; }
        public double[] Offsets { get; set; }
    }

    [SO]
    class SecondProfileProto
    {
        public String Session { get; set; } // yyyy-MM-dd-HH-mm-ss
        public int Second { get; set; }
        public ChannelProfileInfo[] Channels { get; set; }
    }

    [SO]
    class AgencyInputProto
    {
        public uint K { get; set; } // 计数
        public String Function { get; set; }
        public String ID { get; set; } // -1表示void
        public int DataSize { get; set; }
    }

    [SO]
    class AgencyOutputProto
    {
        public uint K { get; set; }
        public String Function { get; set; }
        public String ID { get; set; } // -1表示void
        public int DataSize { get; set; } // -1表示函数不存在
    }

    [SO]
    class SubscriberRequestProto
    {
        public String GUID { get; set; }
        public bool CloseRequest { get; set; }
        public bool CheckOnly { get; set; }
    }

    [SO]
    class SubscriberResponseProto
    {
        public String GUID { get; set; }
        public bool IsClosed { get; set; }
        public int[] DataSizes { get; set; }
    }

    [SO]
    class SegmentProto
    {
        public String GUID { get; set; }
        public Protocol Protocol { get; set; }
        public int TotalSize { get; set; }
        public int TotalSegments { get; set; }
        public int SegmentIndex { get; set; } // 0~
        public int SegmentSize { get; set; }
    }

    [SO]
    class RoundTripTimeProto
    {
        public int Milliseconds { get; set; }
    }
}